<template>
  <div>
    <TopFilter ref="formpanel" :list="formList" :cols="3" :rows="2" labelWidth="110" :collapse="false" @filterChange="changeHandle"></TopFilter>
    <!-- @formChange="formchangeFun" -->
    <!-- :isSubmitBtn="true" -->

    <FilterTable
      ref="table"
      :columns="columns"
      :isColumnFilter="false"
      columnsRef="partPartOtherPartCirculateHandleIndex"
      :isToperInfo="false"
      :params="fetchParams"
      :datakey="'rows'"
      height="300"
      :onSyncTableData="changetablelist"
      :onRowSelectChange="columns => (this.selColumn = columns)"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <!-- :fetchapi="fetchApi" -->
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button>
        <el-button size="small" type="primary" @click="point">打印</el-button>
        <el-button size="small" type="primary" :loading="exportLoading" @click="requestExportData">导出</el-button>
      </template>
    </FilterTable>

    <Drawer
      ref="tablesingleCopy"
      :visible.sync="inOutTypeVisible"
      :title="dialogTitle"
      destroyOnClose
      :width="920"
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <inOutType :rowData="formData" :type.sync="this.type" @close="closeHandler" @changedata="changedata" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import InOutType from './inOutType';
export default {
  components: {
    InOutType
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑' };
    this.type = '';
    return {
      formList: this.createFrom(),
      columns: this.createTableColumns(),
      fetchParams: {},
      inOutTypeVisible: false,
      formData: {},
      dialogTitle: '',
      exportLoading: false // 导出
    };
  },
  methods: {
    createFrom() {
      return [
        {
          type: 'RANGE_DATE',
          label: '借还日期',
          fieldName: 'inOutDate'
        },
        {
          type: 'SELECT',
          label: '借还类型',
          fieldName: 'inOutType',
          itemList: [
            { text: '借入入库', value: '82491003' },
            { text: '还入入库', value: '82491004' },
            { text: '借出出库', value: '82491011' },
            { text: '还出出库', value: '82491012' }
          ]
        },
        {
          type: 'INPUT',
          label: '对方单位名称',
          fieldName: 'companyName'
        },
        {
          type: 'INPUT',
          label: '单据编号',
          fieldName: 'orderNo'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          align: 'center',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          // width: 150,
          fixed: 'left',
          align: 'center',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
                <el-button size="mini" type="text" onClick={() => this.delLabour(props.row)}>
                  删除
                </el-button>
              </div>
            );
          }
        },
        {
          title: '单据编号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true
        },
        {
          title: '借还类型',
          dataIndex: 'inOutType',
          sorter: true,
          filter: true
        },
        {
          title: '对应单编号',
          dataIndex: 'lastOrderNo',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{this.createDictText(props.row.billTypeCode, '8210')}</span>;
          // }
        },
        {
          title: '对方单位名称',
          dataIndex: 'companyName',
          sorter: true,
          filter: true
        },
        {
          title: '借还日期',
          dataIndex: 'inOutDate',
          sorter: true,
          filter: true
          // hidden: true
        },
        {
          title: '单据状态',
          dataIndex: 'orderOtatus',
          sorter: true,
          filter: true
          // render: props => {
          //   const pyt = pinyin(props.row.labourName, { style: 4 })
          //     .join('')
          //     .toUpperCase();
          //   return <span>{pyt}</span>;
          // }
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{this.createDictText(props.row.isCommonIdentity, '1004')}</span>;
          // }
        },
        {
          title: '仓库代码',
          dataIndex: 'storageCode',
          sorter: true,
          filter: true
        },
        {
          title: '仓库名称',
          dataIndex: 'storageName',
          width: 150,
          sorter: true,
          filter: true
        },
        {
          title: '操作员',
          dataIndex: 'operator',
          sorter: true,
          filter: true
        }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    addHandle() {
      this.type = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.type = 'edit';
      this.formData = row;
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `配件借还处理${this.conf[this.type]}`;
      this.inOutTypeVisible = true;
    },
    changetablelist() {},
    closeHandler() {
      this.inOutTypeVisible = false;
    },
    changedata() {
      this.fetchParams = { ...this.fetchParams };
      // this.inOutTypeVisible = false;
    },
    delLabour() {},
    // 打印
    point() {},
    // 导出
    requestExportData() {}
  }
};
</script>
